import txios from '../index'
import type { IAccount, IPhone } from './types'
import type { IDataType } from '../types'
import { loginApi } from './types'

export function loginRequest(account: IAccount) {
  return txios.post<IDataType>({
    url: loginApi.Account,
    data: {
      phone: account.userName,
      password: account.userPassword
    }
  })
}
export function phoneCodeRequest(phone: IPhone) {
  return txios.post({
    url: loginApi.phoneCode,
    data: {
      phone: phone.number
    }
  })
}

export function phoneCodeLoginRequest(phone: IPhone) {
  return txios.post<IDataType>({
    url: loginApi.Account,
    data: {
      phone: phone.number,
      captcha: phone.captcha
    }
  })
}

export function getCodeKeyRequest() {
  return txios.post<IDataType>({
    url: loginApi.code,
    interceptorHooks: {
      requestInterceptor: (config: any) => {
        config.data = {
          ...config.data,
          _t: +new Date()
        }
        return config
      }
    }
  })
}
export function getCodeImgRequest(key?: string) {
  return txios.post<IDataType>({
    url: loginApi.codeImg,
    data: {
      key: key,
      qrimg: true
    }
  })
}

export function getCodeStatusRequest(key?: string) {
  return txios.post({
    url: loginApi.codeStatus,
    data: {
      key: key
    }
  })
}
